package com.zhongshengnetwork.rightbe.dbservice;

import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.dbmodel.AddressdbModel;
import com.zhongshengnetwork.rightbe.dbmodel.ChatdbModel;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

import java.util.List;

/**
 * Created by zhongsheng-luojianlan on 16/11/26.
 */

public class ChatdbService {
    //插入或者更新数据
    public static boolean saveOrUpdate(ChatdbModel model){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.saveOrUpdate(model);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //获取数据
    public static List<ChatdbModel> getData(String ownerid){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            if (db.selector(ChatdbModel.class).where("ownerid","==",ownerid) != null)
             return db.selector(ChatdbModel.class).where("ownerid","==",ownerid).findAll();
        } catch (DbException e) {
            e.printStackTrace();
            return null;
        }
        return null;
    }

    //删除数据
    public static boolean deleteData(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.delete(ChatdbModel.class);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

}
